﻿using System.Collections.Generic;
using Autofac;
using ZilLion.Service.Core.ConfigManager.Manager;
using ZilLion.Service.Core.Ioc;
using ZilLion.Service.TaskPlatform.Controllers.StateContainer;
using ZilLion.Service.TaskPlatform.Domain;
using ZilLion.Service.TaskPlatform.Domain.Respository.GridFs;
using ZilLion.Service.TaskPlatform.Domain.Respository.Interface;
using ZilLion.Service.TaskPlatform.Domain.Respository.Sqlite;
using ZilLion.Service.TaskPlatform.Domain.Respository.Sqlserver;

namespace ZilLion.Service.TaskPlatform.Controllers
{
    public class ComponentLoader : ComponentLoaderBase
    {
        public override void Register(ContainerBuilder builder)
        {
            base.Register(builder);
            RegisterTypeSingleInstance<TaskRunStateContainer>();
            RegisterTypeSingleInstance<NodeRunStateContainer>();
            
            #region 注册组件

            if (ZilLionConfigurationManager.GetConfigInstance<TaskManagerServiceConfig>().ReponsitoryType == ReponsitoryType.Server)
            {
                RegisterTypePerLifetimeScope<NodeInfoRespository, INodeInfoRespository>();
                RegisterTypePerLifetimeScope<NodePerformanceMonitorRespository, INodePerformanceMonitorRespository>();
                RegisterTypePerLifetimeScope<NodeRunMonitorRespository, INodeRunMonitorRespository>();
                RegisterTypePerLifetimeScope<TaskCommandRespository, ITaskCommandRespository>();
                RegisterTypePerLifetimeScope<TaskConfigRespository, ITaskConfigRespository>();
                RegisterTypePerLifetimeScope<TaskModuleConfigRespository, ITaskModuleConfigRespository>();
                RegisterTypePerLifetimeScope<TaskStateRespository, ITaskStateRespository>();
                RegisterTypePerLifetimeScope<MongoTaskPackageRepository, ITaskPackageRespository>();
                
            }
            else
            {
                RegisterTypePerLifetimeScope<SqliteNodeInfoRespository, INodeInfoRespository>();
                RegisterTypePerLifetimeScope
                    <SqliteNodePerformanceMonitorRespository, INodePerformanceMonitorRespository>();
                RegisterTypePerLifetimeScope<SqliteNodeRunMonitorRespository, INodeRunMonitorRespository>();
                RegisterTypePerLifetimeScope<SqliteTaskCommandRespository, ITaskCommandRespository>();
                RegisterTypePerLifetimeScope<SqliteTaskConfigRespository, ITaskConfigRespository>();
                RegisterTypePerLifetimeScope<SqliteTaskModuleConfigRespository, ITaskModuleConfigRespository>();
                RegisterTypePerLifetimeScope<SqliteTaskStateRespository, ITaskStateRespository>();
                RegisterTypePerLifetimeScope<LocalTaskPackageRepository, ITaskPackageRespository>();
            }
           

            #endregion
        }

        public override Dictionary<string, string> InterceptJwtpayload(Dictionary<string, string> formpayload)
        {
            return formpayload;
        }
    }
}